/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.DirectoryMapper;
import cn.qidisoft.edu.hzjt.model.Directory;
import cn.qidisoft.edu.hzjt.service.IDirectoryService;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: CatalogServiceImpl.java, v 0.1 2018年9月28日 上午9:17:27 Administrator hhl $
 */
@Service("directoryService")
public class DirectoryServiceImpl implements IDirectoryService {
    @Autowired
    private DirectoryMapper directoryMapper;

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryList(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public List<Directory> queryList(Directory directory) {
        try {
            return directoryMapper.queryList(directory);

        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryByPK(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public Directory queryByPK(Directory directory) {
        try {
            return directoryMapper.queryByPK(directory);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#add(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void add(Directory directory) {
        try {
            directoryMapper.add(directory);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#update(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void update(Directory directory) {
        try {
            directoryMapper.update(directory);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#delete(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void delete(Directory directory) {
        try {
            directoryMapper.delete(directory);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryPageList(cn.qidisoft.microClass.resource.model.basis.Catalog, cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<Directory> queryPageList(Directory directory, Page page) {
        try {

            int c = directoryMapper.queryPageListcount(directory);
            int totalRecords = 0;
            totalRecords = (int) c;

            PaginationBean<Directory> pageHolder = new PaginationBean<Directory>(page,
                totalRecords);

            List<Directory> resultList = directoryMapper.queryPageList(directory,
                new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#validation(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public int validation(Directory directory) {
        try {
            return directoryMapper.validation(directory);
        } catch (Exception e) {
            e.printStackTrace();
            return -99;
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IDirectoryService#selectProjectByid(cn.qidisoft.edu.hzjt.model.Directory)
     */
    @Override
    public List<Directory> selectProjectByid(Directory data1) {
        try {
            return directoryMapper.selectProjectByid(data1);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IDirectoryService#getUserLevel(cn.qidisoft.edu.hzjt.model.Project)
     */
    @Override
    public List<Directory> getUserLevel(Directory data) {
        try {
            return directoryMapper.getUserLevel(data);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IDirectoryService#selecdirectory_principal(cn.qidisoft.edu.hzjt.model.Directory)
     */
    @Override
    public List<Directory> selecdirectory_principal(Directory data1) {
        try {
            return directoryMapper.selecdirectory_principal(data1);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

}
